home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 1 / CU Amiga Magazine CD-ROM Special Edition (1995)(EMAP Images)(GB)[Issue 1995-11].iso / Aminet / comm / tcp / AmiTCPsdk_40.lha / AmiTCP-4.0 / src / netlib / _close.c < prev    next >
C/C++ Source or Header  |  1994-09-29  |  1KB  |  86 lines

  1. RCS_ID_C="$Id: _close.c,v 4.1 1994/09/29 23:09:02 jraja Exp $";
  2. /*
  3.  *      _close.c - close a file (SAS/C)
  4.  *
  5.  *      Copyright © 1994 AmiTCP/IP Group, 
  6.  *                       Network Solutions Development Inc.
  7.  *                       All rights reserved.
  8.  */
  9.  
  10. #include <ios1.h>
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include <dos.h>
  14. #include <proto/dos.h>
  15. #include <errno.h>
  16. #include <bsdsocket.h>
  17.  
  18. int 
  19. __close(int fd)
  20. {
  21.   struct UFB *ufb;
  22.  
  23.   /*
  24.    * Check for the break signals
  25.    */
  26.   __chkabort();
  27.  
  28.   /*
  29.    * Find the ufb *
  30.    */
  31.   if ((ufb = __chkufb(fd)) == NULL) {
  32.     /* __chkufb sets the errno to EBADF */
  33.     return -1;
  34.   }
  35.  
  36.   /*
  37.    * Check if close is not needed
  38.    */
  39.   if ((ufb->ufbflg & (UFB_NC | UFB_CLO)) != UFB_NC) {
  40.  
  41.     /*
  42.      * Empty flags mean empty ufb
  43.      */
  44.     if (ufb->ufbflg == 0) {
  45.       errno = EBADF;
  46.       return -1;
  47.     }
  48.  
  49.     /*
  50.      * Close the file
  51.      */
  52.     if (!(ufb->ufbflg & UFB_SOCK) && ufb->ufbfh != NULL) {
  53.       Close(ufb->ufbfh);
  54.       
  55.       /*
  56.        * Remove the file if it was temporary
  57.        */
  58.       if (ufb->ufbflg & UFB_TEMP && ufb->ufbfn != NULL) 
  59.     remove(ufb->ufbfn);
  60.     }
  61.  
  62.   }
  63.  
  64.   /*
  65.    * Free the file name
  66.    */
  67.   if (ufb->ufbfn != NULL) {
  68.     free(ufb->ufbfn);
  69.     ufb->ufbfn = NULL;
  70.   }
  71.  
  72.   /*
  73.    * Clear the flags to free this ufb
  74.    */
  75.   ufb->ufbflg = 0;
  76.   ufb->ufbfh = NULL; /* just in case */
  77.  
  78.   /* 
  79.    * closes the socket OR the file mark
  80.    */
  81.   CloseSocket(fd);
  82.   
  83.   return 0;
  84. }
  85.  
  86.